home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / D-G / FastEddie2.cpt / FastEddie2 / debug.c next >
Encoding:
C/C++ Source or Header  |  1985-10-05  |  4.3 KB  |  137 lines  |  [TEXT/FstE]

  1.       /******************************************************/
  2.       /* FstEdC.c .. also A, B, 1, 2, & .h                  */
  3.       /*                                                    */
  4.       /* max_test ..    test for MAX_TEXT approaching       */
  5.       /* open_to_buff ..open file to new buff_hndl          */
  6.       /* set_windows .. set and retrieve from windows menu  */
  7.       /******************************************************/
  8. #include <FstEd.h>
  9.  
  10.       /************************************************/
  11.       /* max_test .. test for MAX_TEXT approaching:   */
  12.       /* alert user every dozen strokes if length is  */
  13.       /* within MAX_WARN of MAX_TEXT                  */
  14.       /************************************************/
  15. max_test (node)
  16. struct win_node *node;
  17. {
  18.   char str [LINE_LNGTH], str2 [LINE_LNGTH]; 
  19.   int length_left;
  20.   
  21.   length_left = MAX_TEXT - (*node->te_hndl)->telength;
  22.   if ( (length_left < MAX_WARN && node->strokes > 11)
  23.         || length_left <= 0
  24.       ) 
  25.     { if (node->strokes)  node->strokes = 1;
  26.       itoa ( (long) (*node->te_hndl)->telength, str);
  27.       itoa (MAX_TEXT, str2);
  28.       paramtext (str, str2, "", "");
  29.       notealert (SIZE_ALRT, NIL);
  30.     }
  31.   if (length_left <= 0) return KLOSE;
  32.   return OK;
  33. }
  34.       
  35.       /************************************************/
  36.       /* open_to_buff .. open file to new buff_hndl   */
  37.       /* create buff_hndle of length lngth and fill   */
  38.       /* with file title from vref                    */
  39.       /************************************************/
  40. open_to_buff (title, vref, buff_hndl, lngth)
  41. char *title;
  42. int vref;
  43. handle *buff_hndl;
  44. long *lngth;
  45. {
  46.   int ref_num;
  47.   char str [LINE_LNGTH], str2 [LINE_LNGTH];
  48.   
  49.   if (fsopen (title, vref, &ref_num) != noerr)  return ERR;
  50.   geteof (ref_num, xlngth);
  51.   if (*lngth > MAX_TEXT )  
  52.     { fsclose (ref_num);
  53.       itoa (*lngth, str);
  54.       itoa (MAX_TEXT, str2);
  55.       paramtext (str, str2, "", "");
  56.       notealert (SIZE_ALRT, NIL);
  57.       return ERR;
  58.     } 
  59.     
  60.   if (!mem_check (*lngth) ) 
  61.     { fsclose (ref_num);  return ERR; }
  62.   *buff_hndl = newhandle (*lngth);
  63.   fsread (ref_num, lngth, **buff_hndl);
  64.   fsclose (ref_num);
  65.   return OK;
  66. }
  67.  
  68.       /*****************************************************/
  69.       /* set_windows .. set and retrieve from windows menu */
  70.       /* bring choosen window to the front unless command  */
  71.       /* is down, in which case, insert window contents    */
  72.       /*****************************************************/
  73. set_windows (node, event, menus, item)
  74. struct win_node *node;
  75. eventrecord event;
  76. menuhandle menus [];
  77. int item;
  78. {
  79.   int i;
  80.   windowptr nxt_wp;
  81.   long refcon, lngth;
  82.   static windowptr menu_wp [MAX_ITEMS];
  83.   struct win_node *sel_node;
  84.   tehandle te_hndl;
  85.   char *text, str [LINE_LNGTH], str2 [LINE_LNGTH];
  86.     
  87.   if (item > 0)
  88.     { if (!(event.modifiers & cmdkey) )
  89.         return selectwindow (menu_wp [item - 1]);
  90.         
  91.       refcon = ( (windowpeek) menu_wp [item - 1])->refcon;
  92.       sel_node = (struct win_node *) refcon;
  93.  
  94.       paramtext (sel_node->title, node.title, "","");
  95.       i = cautionalert (INSRT_ALRT, NIL);
  96.       if (i != OK) return ERR; 
  97.  
  98.       text = *(*sel_node->te_hndl)->htext;
  99.       lngth = (*sel_node->te_hndl)->telength;
  100.       
  101.       if ( !mem_check (lngth) ||
  102.            lngth + (*node->te_hndl)->telength > MAX_TEXT
  103.          )
  104.         { itoa (lngth + (*node->te_hndl)->telength, str);
  105.           itoa (MAX_TEXT, str2);
  106.           paramtext (str, str2, "", "");
  107.           notealert (SIZE_ALRT, NIL);
  108.           return ERR;
  109.         }  
  110.       teinsert (text, lngth, node->te_hndl);
  111.       sel_scroll (NIL, NIL, node);
  112.       node->strokes++;
  113.       return OK;
  114.     }
  115.     
  116.   deletemenu (WINDOWS);                   /* reset menu: */
  117.   disposemenu (menus [WINDOWS]);
  118.   menus [WINDOWS] = newmenu (WINDOWS, "windows");
  119.  
  120.   for (i = 0; i < MAX_ITEMS; )
  121.     { nxt_wp = ( (windowpeek) node->wp)->nextwindow;
  122.       if (nxt_wp == NIL) break; 
  123.       if ( ( (windowpeek) nxt_wp)->windowkind != userkind)
  124.         { nxt_wp = ( (windowpeek) node->wp)->nextwindow;
  125.           continue;
  126.         }
  127.  
  128.       refcon = ( (windowpeek) nxt_wp)->refcon;
  129.       node = (struct win_node *) refcon;
  130.       appendmenu (menus [WINDOWS], node->title);
  131.       menu_wp [i++] = node->wp; 
  132.     }
  133.   if (i == 0) appendmenu (menus [WINDOWS], "(empty");
  134.   insertmenu (menus [WINDOWS], FONT);
  135. }
  136.  
  137.